using Microsoft.Xna.Framework;
using SCSEngine.Mathematics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SCSEngine.Utils.Entities.Component
{
    public class Vector2Component : IVector2Component
    {
        public Vector2Component()
        {
        }

        public Vector2Component(float x, float y)
        {
            this.val.X = x;
            this.val.Y = y;
        }

        public Vector2Component(Vector2 initValue)
        {
            this.val = initValue;
        }

        public void Initialize()
        {
        }

        private Vector2 val;

        public Vector2 Direction
        {
            get { Vector2 dir = val; dir.Normalize(); return dir; }
            set { float length = val.Length(); value.Normalize(); this.val = value * length; }
        }

        public float Angle
        {
            get { return GMath.NegativeAngle(this.val) - MathHelper.PiOver2; }
            set { this.val = this.Length * GMath.DirectedVector(value); }
        }

        public float Length
        {
            get { return this.val.Length(); }
            set { Vector2 dir = this.val; dir.Normalize(); this.val = value * dir; }
        }

        public Vector2 Value
        {
            get
            {
                return this.val;
            }
            set
            {
                this.val = value;
            }
        }

        public float X
        {
            get
            {
                return this.val.X;
            }
            set
            {
                this.val.X = value;
            }
        }

        public float Y
        {
            get
            {
                return this.val.Y;
            }
            set
            {
                this.val.Y = value;
            }
        }
    }
}